package com.zhixiang.xaec.service.system.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.xaec.dao.system.TemplateDao;
import com.zhixiang.xaec.entity.system.Template;
import com.zhixiang.xaec.service.system.TemplateService;
@Service
public class TemplateServiceImpl extends BaseServiceImpl<Template, Long> implements TemplateService
{

    @Override
    public String delete(String[] ids)
    {
       for(String id:ids){
           getDao().remove(Long.valueOf(id));
       }
        return null;
    }
    
    @Override
    public Template save(Template template){      
        if(template.gettDefault()==null){
            template.settDefault(Integer.valueOf(0));
            getDao().save(template);
        }else if(template.gettDefault().equals(Integer.valueOf(1))){
            getDao().save(template);
            getDao().update("update Template t set t.tDefault = 0  where t.tDefault= 1  And t.id !=? And t.tType.detailId=?",
            new Object[]{template.getId(),template.gettType().getDetailId()});
        }
        
        return template;
    }

    @Override
    @Resource(type=TemplateDao.class)
    public void setBaseDao(BaseDao<Template, Long> dao)
    {
        setDao(dao);
        
    }

    //判断模版是否被使用的方法，返回查询到的list的size的值，前台根据该值判断，如果大于0，则判定为被使用
    @Override
    public Integer checkUsed(String id, String ttName)
    {        
       Integer count=0;
       QueryFilter queryFilter=new QueryFilter();
       queryFilter.addFilter("Q_template.id_L_EQ", id);
       
       if("物料模版".equals(ttName)){
          
       }else if("工艺模版".equals(ttName)){
           
       }else if("工序模版".equals(ttName)){
           
       }else {
           
       }
        return count;
    }

}
